define(
    function (require) {
        var BaseFormModel = require('common/FormModel');
        var Data = require('./Data');
        var datasource = require('er/datasource');
        var util = require('common/util');

        function FormModel() {
            BaseFormModel.apply(this, arguments);
            var entityName = this.getUrlType();
            this.addData(new Data(entityName));
        }

        FormModel.prototype.prepare = function () {
            BaseFormModel.prototype.prepare.call(this);
            this.set('uploadUrl', '/api/upload/4');

            if (this.get('formType') === 'update') {
                var type = this.get('type');
                if (util.isString(type) && !util.isEmpty(type)) {
                    this.set('type', [type]);
                }
            }

            var mallid = this.get('mallid');
            if (util.isString(mallid)) {
                if (mallid.indexOf('_') === -1) {
                    mallid = 'mall_' + mallid;
                }
                this.set('mallid', [mallid]);
            }
            this.prepareObject('chargePerson', 'legalPerson');
        };

        FormModel.prototype.uploaderIds = [
            'logo-pic', 'gate-pic', 'business-license-pic',
            'health-license-pic', 'tax-pic', 'id-pic1', 'id-pic2', 'qrcode'
        ];

        FormModel.prototype.save = function(entity) {
            return BaseFormModel.prototype.save.apply(this, arguments);
        };

        FormModel.prototype.validateEntity = function (entity) {
            var errorMsg = [];
            if (errorMsg.length > 0) {
                return errorMsg;
            }
            return BaseFormModel.prototype.validateEntity.apply(this, arguments);
        };

        require('er/util').inherits(FormModel, BaseFormModel);
        return FormModel;
    }
);
